<?php
/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
namespace App\Core;
include_once 'Test.class.php';

Class Router{
    private $ctrUrl = 1;
    private $modulename = null;
    private $actionname = null;
    private $param_arr = array();
    

    public function __construct($ctrUrl = 1){
        $this->ctrUrl = $ctrUrl;
    }
    
    public function onProgress(){
        $res_arr = $this->onUrl();
        $this->modulename = $res_arr[MODULE];
        $this->actionname = $res_arr[ACTION];
        $this->param_arr = array_slice($res_arr, 2);
        $mod = MODULE_DIR.'\\'.$this->modulename;
        $mod_obj = \App\Core\Factory::createObj($mod);
        call_user_func_array (array($mod_obj, $this->actionname), array($this->param_arr));
    }   

    public function onUrl(){
        $url_arr = array();
        $res_arr =array();
        $url_arr = explode('&',ltrim(strstr($_SERVER['REQUEST_URI'],'?'),'?'));
        
        foreach($url_arr as $k => $v){
            $tmp_arr=explode('=',$v);
            $res_arr[$tmp_arr[0]] = $tmp_arr[1];   
        }
        return $res_arr;
    }   
}
